<?php

/*
 * email/load-index.phtml
 */
?>
<?php
$emails = $this->emails;
?>
<div class="list-container">
    <table class="table table-striped list-table" border="1">
	<thead>
	    <tr>
		<td width="10%">ID</td>
		<td width="30%">Libellé</td>
                <td width="20%">Email</td>
		<td width="30%">Description</td>
		<td width="10%">&nbsp;</td>
	    </tr>
	</thead>
	<tbody>
	    <?php foreach ($emails as $d): ?>
    	    <tr>
    		<td><?php echo $d->id; ?></td>
    		<td>
    		    <a href="#" class="edit-email" data-type="text" data-pk="<?php echo $d->id; ?>" data-name="libelle"><?php echo $d->libelle; ?></a>
    		</td>
                <td>
    		    <a href="#" class="edit-email" data-type="text" data-pk="<?php echo $d->id; ?>" data-name="email"><?php echo $d->email; ?></a>
    		</td>
    		<td>
    		    <a href="#" class="edit-email" data-type="text" data-pk="<?php echo $d->id; ?>" data-name="description"><?php echo $d->description; ?></a>
    		</td>
		<td>
                    
                            <a href='#' class='deleteTemplate' data-id='<?php echo $d->id; ?>' onclick='return erase(<?php echo $d->id ?>);'>
					<img src='<?php echo $this->basePath() . '/img/rhx/delete-16x16.png' ?>' alt='Supprimer' title='Supprimer'>
			    </a>
                </td>
    	    </tr>
	    <?php endforeach; ?>
	</tbody>
    </table>
</div>

<script type="text/javascript">
// Démarrage
$(function(){
    // Editable
    //libelle = $('#data-libelle').val();
    //email = $('#data-email').val();
    //function isValidEmailAddress(email) {
      //      var pattern = new RegExp(/^[a-z0-9._-]+@[a-z0-9._-]{2,}\.[a-z]{2,4}$/);
        //    return pattern.test(email);
        //     };
     /*if( !isValidEmailAddress( email ) )
                 {
                    alert("L 'adresse émail n 'est pas valide"); 
                    return false;
                 }
    if (libelle.length < 1){
		alert("Le libellé de l ' Email est trop court ou vide");

		return false;
            }*/
    $('.edit-email').editable({
	title: "Edition de l ' email",
	url: '<?php echo $this->url('RHX/default', array('controller'	 => 'email', 'action'	 => 'edit')); ?>'
    });
});
</script>
<script type='text/javascript'>
    function erase(id)
		{
		    var conf = confirm("Voulez-vous vraiment effacer l 'adresse émail numéro "+id+" ?");
		    if (conf != true)
			return false;
		    var urlDelete = "<?php echo $this->url('RHX/default', array('controller'	 => 'email', 'action'	 => 'erase')) ?>/" + id;
		    var ajax = $.ajax({
			type: 'post',
			url: urlDelete
		    });
		    ajax.success(function() {
			location.reload();
		    });
		    ajax.error(function() {
			alert('Une erreur est survenue');
		    });
		    return false;
		}
</script>
